#pragma once

#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>

namespace emugl {

	class ConditionVariable;

	// Simple wrapper class for mutexes.
	class Mutex {
	public:
		// Constructor.
		Mutex() {
			::InitializeCriticalSection(&mLock);
		}

		// Destructor.
		~Mutex() {
			::DeleteCriticalSection(&mLock);
		}

		// Acquire the mutex.
		void lock() {
			::EnterCriticalSection(&mLock);
		}

		// Release the mutex.
		void unlock() {
			::LeaveCriticalSection(&mLock);
		}

		// Helper class to lock / unlock a mutex automatically on scope
		// entry and exit.
		class AutoLock {
		public:
			AutoLock(Mutex& mutex) : mMutex(&mutex) {
				mMutex->lock();
			}

			~AutoLock() {
				mMutex->unlock();
			}
		private:
			Mutex* mMutex;
		};

	private:
		CRITICAL_SECTION mLock;
	};

}  // namespace emugl
